package edu.chl.dat255.bluebanana.utils;

import edu.chl.dat255.bluebanana.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
	private int galleryItemBackground;
	private Context context;
	
	public static Integer[] imageIds = {R.drawable.car_icon, R.drawable.meeting_icon, R.drawable.night_icon};
	
	public ImageAdapter(Context context) {
        this.context = context;
        TypedArray typedArray = context.obtainStyledAttributes(R.styleable.Gallery1);
        galleryItemBackground = typedArray.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
        typedArray.recycle();
    }

	@Override
	public int getCount() {
		return imageIds.length;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return imageIds[position];
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imageView = new ImageView(context);

        imageView.setImageResource(imageIds[position]);
//        imageView.setLayoutParams(new Gallery.LayoutParams(150, 100));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setBackgroundResource(galleryItemBackground);
        imageView.setFocusable(true);
        imageView.setFocusableInTouchMode(true);

        return imageView;
	}
	
}
